package com.iflytek.aisol.audit.iflytek.strategy.manage.controller;

import com.iflytek.aisol.audit.iflytek.strategy.manage.dto.GrayConfigDTO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.common.entity.R;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.GrayConfigQuery;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.GrayConfigVO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.PageDTO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.service.GrayConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/gray-config")
@Slf4j
@Api(tags = "灰度策略配置管理")
public class GrayConfigController {
    @Autowired
    private GrayConfigService grayConfigService;

    /**
     * 新增灰度策略接口
     */
    @PostMapping
    @ApiOperation(value = "新增灰度策略接口")
    public R<?> add(@RequestBody GrayConfigDTO grayConfigDTO){
        log.info("插入的数据为：{}", grayConfigDTO);
        grayConfigService.add(grayConfigDTO);
        return R.success();
    }

    /**
     * 删除灰度策略接口
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除灰度策略接口")
    public R<?> delete(@PathVariable Long id){
        grayConfigService.delete(id);
        return R.success();
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询灰度配置")
    public R<PageDTO<GrayConfigVO>> queryGrayNamePage(GrayConfigQuery query) {
        log.info("分页查询：{}",query);
        PageDTO<GrayConfigVO> result = grayConfigService.queryGrayNamePage(query);
        return R.success(result);
    }
}
